<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
            * {
      margin: 0;
      padding: 0;
    }

    .father {
      position: relative;
      width: 300px;
      height: 300px;
      padding: 5px;
      border: 10px solid red;
      margin: 100px;
      background-color: pink;
    }

    .son {
      width: 100px;
      background-color: purple;
    }
    </style>
</head>
<body>
    <div class="father">
        <div class="son">
          里面包含一些文字
          里面包含一些文字
          里面包含一些文字
        </div>
      </div>
</body>
</html>
<script>
// 获取元素
const father =document.querySelector('.father')
const son = document.querySelector('.son')
console.log(father.offsetLeft)
console.log(father.offsetTop)
console.log('----')
// 获取元素的大小
// offsetWidth 包含元素的宽度 + padding + border, 不包含 margin
console.log(father.offsetWidth)
console.log(son.offsetWidth)

</script>